<template>
  <div class="header-user">
    <span>
      <a-dropdown>
        <a class="ant-dropdown-link"
           @click="e => e.preventDefault()">
<!--          <a-avatar :size="30"-->
<!--                    src=""></a-avatar>-->
          <span class="header-user-name">admin</span>
          <a-icon type="down"/>
        </a>
        <a-menu slot="overlay">
          <a-menu-item>
            <a href="javascript:void(0)"
               @click="modifyPasswordModule.show()">修改密码</a>
          </a-menu-item>
          <a-menu-item>
            <a href="javascript:void(0)"
               @click="logout">退出</a>
          </a-menu-item>
        </a-menu>
      </a-dropdown>
    </span>

    <a-modal title="修改密码"
             v-model="modifyPasswordModule.visible"
             :footer="null"
             :maskClosable="false">
      <ModifyPassword v-if="modifyPasswordModule.visible"
                      @submit="modifyPasswordModule.submit"
                      @cancel="modifyPasswordModule.cancel"/>
    </a-modal>
  </div>
</template>
<script lang="ts">
  import { Component, Vue } from 'vue-property-decorator'
  import { VueModule } from '@/utils'
  import loading from '@/components/libs/loading/index'
  import { Action, Getter } from 'vuex-class'
  import * as actionTypes from '@/store/actionTypes'
  import EventBus from '@/constants/eventBus'
  import ModifyPassword from './components/modifyPassword.vue'

  @Component({
    components: {
      ModifyPassword
    },
  })
  export default class FrameHeaderUser extends Vue {

    @Action(actionTypes.LOGOUT)
    private logout!: any
    @Action(actionTypes.REGET_ADMIN_INFO)
    private regetAdminInfo!: () => Promise<any>

    private switchEnterpriseModule = VueModule.create({
      submit: (target: any) => {
        this.regetAdminInfo().then(() => {
          loading.show()
          window.location.reload()
        })
      },
    })
    private personalInfoModule = VueModule.create({
      submit: (target: any) => {
        this.regetAdminInfo().then(() => {
          target.hide()
        })
      },
    })
    private modifyPasswordModule = VueModule.create({
      submit: (target: any) => {
        this.success('修改密码成功')
        target.hide()
      },
    })

    protected created() {
      // 监听退出登录
      this.$onBus(EventBus.Frame.logout, () => {
        this.logout()
      })
    }
  }
</script>
